home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Programming / EasyPLUGINs / source / dtpic.e < prev    next >
Encoding:
Text File  |  1998-02-14  |  6.0 KB  |  169 lines

  1. ;/*
  2.  
  3.     ec dtpic
  4.     flushcache
  5.     ec dtpic_test
  6.     dtpic_test
  7.     quit
  8.  
  9.     $VER: DTPic Plugin V1.00
  10.  
  11.     Synopsis: I had the idea of writing this quickly after looking at the bitmap_plugin.
  12.                  Eeek! Not a user friendly way of sticking a picture onto a window.
  13.     
  14.                  Do you want to stick a nice picture in your EasyGui's? Don't want
  15.                  too much bother? Need automatic colour remapping? Here's what you
  16.                  are looking for then.
  17.  
  18.     Written by: Will Harwood (147800.97@swansea.ac.uk)
  19.  
  20.  
  21.     Notes: Apologies for the rather messy implementation, but for colour remapping
  22.              DoDTMethod needs a pointer to a window which does not exist...
  23.     
  24.              This could easily be extended to allow the user to set the screen palette
  25.              as that of the picture (this code is taken for some more comprehensive stuff
  26.              I wrote for a game) but since EasyGUI is designed primarily for Workbench GUI's,
  27.              this seems rather pointless.
  28.     
  29.  
  30.     Please, *please* e-mail me if you find any errors or obvious omissions in the code!
  31.     (Not spelling though.)
  32.  
  33. */
  34.  
  35. OPT OSVERSION=39
  36. OPT MODULE
  37. OPT EXPORT
  38.  
  39. MODULE  'workbench/workbench',
  40.         'exec/ports',
  41.           'datatypes', 
  42.         'intuition/screens', 'intuition/intuition',
  43.         'tools/easygui', 'tools/Exceptions',
  44.           'graphics/gfx', 'graphics/scale',
  45.           'datatypes/datatypes', 'datatypes/datatypesclass', 'datatypes/pictureclass',
  46.           'utility', 'utility/tagitem'
  47.  
  48.  
  49. ENUM PLA_DTPic_Scale=$82010000, PLA_DTPic_Filename
  50.  
  51.  
  52. OBJECT dtpic_plugin OF plugin
  53.     PRIVATE
  54.     object                          /* the datatype object */
  55.     bitmap:PTR TO bitmap            /* a pointer to its bitmap */
  56.     bmh:PTR TO bitmapheader     /* a pointer to the bitmapheader */
  57.     filename:PTR TO CHAR
  58.     scale
  59. ENDOBJECT
  60.  
  61. PROC init(tags=NIL:PTR TO tagitem) OF dtpic_plugin
  62.     DEF t_bitmap=NIL:PTR TO bitmap, t_bmh=NIL:PTR TO bitmapheader
  63.  
  64.     /* Open our own libraries */
  65.     IF NIL=(datatypesbase:=OpenLibrary('datatypes.library', 39)) THEN Raise("dlib")
  66.     IF NIL=(utilitybase:=OpenLibrary('utility.library', 39)) THEN Raise("util") 
  67.  
  68.     self.filename:=GetTagData(PLA_DTPic_Filename, '', tags)
  69.    self.scale:=GetTagData(PLA_DTPic_Scale, FALSE, tags)
  70.  
  71.     /*- Here we come to a circular problem: To use colour remapping I need a pointer to
  72.         the window, but before the window can be opened EasyGUI needs to get the minimum
  73.         dims of the picture. Erk. So I have to open the picture twice, first to get the
  74.         dims, and secondly in render to get the actual picture. -*/
  75.  
  76.     /* Get a new datatypes object from disk, and quit if something went wrong */
  77.     self.object:=NewDTObjectA(self.filename, [DTA_SOURCETYPE, DTST_FILE,
  78.                                              DTA_GROUPID,    GID_PICTURE,
  79.                                              PDTA_REMAP,     TRUE,
  80.                                              0])
  81.  
  82.     IF self.object=0 THEN Raise("FILE")
  83.     
  84.     IF DoDTMethodA(self.object, 0, 0, [DTM_PROCLAYOUT,FALSE,TRUE])=NIL
  85.         DisposeDTObject(self.object)
  86.         self.object:=NIL
  87.         Raise("dt")
  88.     ENDIF
  89.  
  90.     IF GetDTAttrsA(self.object, [PDTA_BITMAPHEADER,{t_bmh}, 0])<>1 THEN Raise("dt")
  91.  
  92.     self.bmh:=t_bmh
  93.     self.bitmap:=0
  94.  
  95. ENDPROC
  96.  
  97. PROC end() OF dtpic_plugin
  98.     IF self.object THEN DisposeDTObject(self.object)
  99.     IF datatypesbase THEN CloseLibrary(datatypesbase)
  100.     IF utilitybase THEN CloseLibrary(utilitybase)
  101. ENDPROC
  102.  
  103. PROC will_resize() OF dtpic_plugin IS self.scale
  104.  
  105. PROC min_size(ta, fh) OF dtpic_plugin IS self.bmh.width, self.bmh.height
  106.  
  107. PROC render(ta, x,y, xs, ys, win:PTR TO window) OF dtpic_plugin
  108.     DEF t_bitmap=NIL:PTR TO bitmap, t_bmh=NIL:PTR TO bitmapheader, tbm=NIL:PTR TO bitmap
  109.  
  110.     /* A rather messy solution to an intractable problem (unless we do something sneaky
  111.         in dtpic_test, but I don't want to have to alter the source). If self.bitmap=NIL
  112.         then this is the first time this procedure hase been called, so we have to close
  113.         the object, and then open it up again. */
  114.     IF (self.bitmap=NIL) AND (self.object)
  115.         DisposeDTObject(self.object)
  116.         self.object:=NewDTObjectA(self.filename, [DTA_SOURCETYPE, DTST_FILE,
  117.                                                      DTA_GROUPID,    GID_PICTURE,
  118.                                                      PDTA_REMAP,     TRUE,
  119.                                              0])
  120.  
  121.         IF self.object=0 THEN Raise("FILE")
  122.         
  123.         IF DoDTMethodA(self.object, win, 0, [DTM_PROCLAYOUT,FALSE,TRUE])=NIL
  124.             DisposeDTObject(self.object)
  125.             self.object:=NIL
  126.             Raise("dt")
  127.         ENDIF
  128.     
  129.         /* GetDTAttrsA returns the number of items of information about the object it was able
  130.             to get, so if it returns any less than two here there's been a problem */
  131.         IF GetDTAttrsA(self.object,
  132.                                 [PDTA_BITMAP,      {t_bitmap},
  133.                                  PDTA_BITMAPHEADER,{t_bmh},
  134.                                  0])<>2 THEN Raise("dt")
  135.     
  136.         self.bitmap:=t_bitmap
  137.         self.bmh:=t_bmh
  138.     ENDIF
  139.     
  140.     IF self.object
  141.         IF self.scale
  142.             /* Use bitmap scale into a temporary bitmap */
  143.             IF NIL=(tbm:=AllocBitMap(win.width, win.height, self.bmh.depth, 0, 0)) THEN Raise("bm")
  144.             BitMapScale([0, 0, self.bmh.width, self.bmh.height, self.bmh.width, self.bmh.height, 
  145.                              0, 0, xs, ys, xs, ys,
  146.                              self.bitmap, tbm, 0, 0, 0, 0, 0]:bitscaleargs)
  147.             BltBitMapRastPort(tbm, 0, 0, win.rport, x, y, xs, ys, $c0)
  148.             FreeBitMap(tbm)
  149.         ELSE
  150.             /* No scaling, so just blit it */
  151.             BltBitMapRastPort(self.bitmap, 0, 0, win.rport, x, y, xs, ys, $c0)
  152.         ENDIF
  153.     ENDIF
  154. ENDPROC
  155.  
  156. PROC set(attr, value) OF dtpic_plugin
  157.     SELECT attr
  158.     CASE PLA_DTPic_Scale
  159.         self.scale:=value
  160.     ENDSELECT
  161. ENDPROC
  162.  
  163. PROC get(attr) OF dtpic_plugin
  164.     SELECT attr
  165.     CASE PLA_DTPic_Scale
  166.         RETURN self.scale, TRUE
  167.     ENDSELECT
  168. ENDPROC
  169.